<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn1">全选</button>
    <button id="btn2">不选</button>
    <button id="btn3">反选</button>
    <br>
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <script>
        // 获取button按钮的元素集合
        var btn = document.getElementsByTagName('button');
        // 获取复选框按钮的元素集合，来改变复选框的选择状态
        var inputs = document.getElementsByTagName('input');

        for(var i = 0; i < btn.length; i++){
            btn[i].onclick = function(){
                    if(this.innerHTML === '全选'){
                        for (var j = 0; j < inputs.length; j++){
                            inputs[j].checked = true;
                        }
                    }else if(this.innerHTML === '反选'){
                        for (var j = 0; j < inputs.length; j++){
                            inputs[j].checked = !inputs[j].checked;
                        }
                    }if(this.innerHTML === '不选'){
                        for (var j = 0; j < inputs.length; j++){
                            inputs[j].checked = false;
                        }
                    }
                }
            }
        }
    </script>
</body>
</html>